#!/usr/bin/perl
# Update the manually edited config file

require '../netebbms-lib.pl';

&ReadParse();

&error_setup($text{'manual_err'});
if (length($in{'consumerkey'}) != 21) {
	&error($text{'twitterclient_consumerkey_emsg'});
}
if (length($in{'consumersecret'}) != 41) {
	&error($text{'twitterclient_consumersecret_emsg'});
}
if (length($in{'accesstokenkey'}) != 50) {
	&error($text{'twitterclient_accesstokenkey_emsg'});
}
if (length($in{'accesstokensecret'}) < 30) {  # need check!
	&error($text{'twitterclient_accesstokensecret_emsg'});
}
if ($in{'timeout'} !~ /^\d+$/) {
	&error($text{'twitterclient_timeout_emsg'});
}
#&error($text{'twitterclient_tweetselect_emsg'});     # need check!


$cfgObj = new Config::Simple(syntax=>'ini');

# account #
$cfgObj->param('account.consumerkey', $in{'consumerkey'});
$cfgObj->param('account.consumersecret', $in{'consumersecret'});
$cfgObj->param('account.accesstokenkey', $in{'accesstokenkey'});
$cfgObj->param('account.accesstokensecret', $in{'accesstokensecret'});

# behavior #
$in{'tweetselect'} =~ s/ //g;
$cfgObj->param('behavior.tweetselect', join(',', split(/\0/, $in{'tweetselect'})));
$cfgObj->param('behavior.timeout', $in{'timeout'});
$in{'hashtags'} =~ s/ //g;
$cfgObj->param('behavior.hashtags', join(',', split(/\0/, $in{'hashtags'})));


$cfgObj->write($config{'twitterclient_conf'});


#print &ui_print_header(undef, $text{'index_title'}, '', undef, 1, 1);
#
#print '%in<br>';
#while (($key, $value) = each(%in)) {
#	print $key,' = ', $value, '<br>';
#}
#
#print '<br>';
#print '<pre>';
#print $cfgObj->dump();
#print '</pre>';
#
#print &ui_print_footer('/', $text{'index'});


&redirect('..');

